﻿using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProductionLine.API.Application.Command.BOM;
using ProductionLine.ErrorCode;
using ProductionLine.Extensions;

namespace ProductionLine.API.Controllers
{
    /// <summary>
    /// BOM
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class BOMController : ControllerBase
    {
        IMediator mediator;
        ILogger<BOMController> logger;

        public BOMController(IMediator mediator, ILogger<BOMController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 新增BOM
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddBOM(AddBOMCommand request)
        {
            logger.LogInformation("新增BOM成功");
            return await mediator.Send(request);
        }
        /// <summary>
        /// BOM组成
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<BOMDTO>>> GetBOM([FromQuery] GetBOMCommand request)
        {
            logger.LogInformation("查询BOM成功");
            return await mediator.Send(request);
        }
    }
}
